home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / iff2pc.lha / paz / IFFtoWAV.s < prev   
Encoding:
Text File  |  1993-04-18  |  6.5 KB  |  307 lines

  1.  
  2.  
  3. * * * >>>> IFF to WAV  Converter <<<< * * *
  4. *                      *
  5. *  Converts IFF samples to Windows' .WAV  *
  6. *                      *
  7. *   Written by Geert Coelmont on 9/1/93   *
  8. *   This source is freely distributable   *
  9. *   as long as NOTHING's altered in ANY   *
  10. *   way. If you want more nice software   *
  11. *   then write me at:              *
  12. *                      *
  13. *      Eikenlaan  21              *
  14. *      3740   BILZEN              *
  15. *      B E L G I U M              *
  16. *                      *
  17. * * * * * * * * * * * * * * * * * * * * * *
  18.  
  19.  
  20. IFFtoWAV:
  21.     movem.l    d0-a6,-(sp)
  22.     subq.l    #1,d0
  23.     move.l    d0,arglen
  24.     move.l    a0,argptr
  25.  
  26.     lea    doslibrary(pc),a1
  27.     moveq    #0,d0
  28.     move.l    $4.w,a6
  29.     jsr    -408(a6)        ; open library
  30.     move.l    d0,dosbase
  31.  
  32.     move.l    d0,a6
  33.     moveq    #0,d0
  34.     jsr    -60(a6)            ; find std_out
  35.     move.l    d0,texthandle
  36.     beq    error1
  37.  
  38. CHECKPARAMETERS:
  39.     move.l    arglen(pc),d0
  40.     tst.l    d0
  41.     beq.w    error1
  42.     subq.l    #1,d0
  43.     move.l    argptr(pc),a0
  44. .loop:    clr.l    d2
  45.     move.b    (a0),d1
  46.     cmp.b    #"-",d1            ; check for switch
  47.     bne.s    checkfilenames
  48.     move.b    1(a0),d1
  49.     cmp.b    #"8",d1            ; 8: 8 bit translation
  50.     bne.w    error1            ; else: illegal switch
  51.     move.w    #1,eightbit
  52.     lea.l    3(a0),a0
  53.     subq.l    #3,d0
  54.  
  55. CHECKFILENAMES:
  56.     move.l    a0,infilenameptr    ; next param is Infile
  57.     move.l    d0,d1
  58. .loop1:    cmp.b    #32,(a0)+        ; find next space
  59.     beq.s    .exit1
  60.     dbf    d1,.loop1
  61.     bra.w    error1
  62. .exit1:    clr.b    -1(a0)            ; terminate Infile
  63.     move.l    a0,outfilenameptr    ; next param is Outfile
  64.     tst.l    d1
  65.     ble.w    error1
  66. .loop2:    move.b    (a0)+,d0
  67.     cmp.b    #32,d0            ; find eoln or next space
  68.     beq.s    .exit2
  69.     cmp.b    #10,d0
  70.     beq.s    .exit2
  71.     dbf    d1,.loop2
  72.     bra.w    error1
  73. .exit2:    clr.b    -1(a0)            ; terminate Outfile
  74.  
  75. OPENIN:    move.l    dosbase(pc),a6
  76.     move.l    infilenameptr(pc),d1
  77.     move.l    #1005,d2        ; 'MODE_OLDFILE'
  78.     jsr    -30(a6)            ; open infile
  79.     move.l    d0,inhandle
  80.     bne.s    openout
  81.  
  82.     lea    errorinfile(pc),a1
  83.     move.l    a1,textptr
  84.     bra    error1
  85.  
  86. OPENOUT:move.l    dosbase(pc),a6
  87.     move.l    outfilenameptr(pc),d1
  88.     move.l    #1006,d2        ; 'mode_newfile'
  89.     jsr    -30(a6)            ; open outfile
  90.     move.l    d0,outhandle
  91.     bne.s    getinlength
  92.  
  93.     lea    erroroutfile(pc),a1
  94.     move.l    a1,textptr
  95.     bra    error2
  96.  
  97. GETINLENGTH:
  98.     move.l    infilenameptr(pc),d1
  99.     moveq    #-2,d2
  100.     move.l    dosbase(pc),a6
  101.     jsr    -84(a6)            ; find lock
  102.     move.l    d0,lock
  103.     move.l    d0,d1
  104.     move.l    #infoblock,d2
  105.     move.l    dosbase(pc),a6
  106.     jsr    -102(a6)        ; examine
  107.     lea.l    infoblock,a0
  108.     move.l    124(a0),filelength
  109.     move.l    lock(pc),d1
  110.     move.l    dosbase(pc),a6
  111.     jsr    -90(a6)            ; unlock
  112.  
  113. ALLOCMEM:
  114.     move.l    filelength(pc),d0
  115.     moveq    #1,d1
  116.     move.l    $4.w,a6
  117.     jsr    -198(a6)        ; alloc public memory
  118.     move.l    d0,dataptr
  119.     bne.s    readsample
  120.  
  121.     lea.l    outofmem(pc),a1
  122.     move.l    a1,textptr
  123.     bra.w    error3
  124.  
  125. READSAMPLE:
  126.     move.l    inhandle(pc),d1
  127.     move.l    dataptr(pc),d2
  128.     move.l    filelength(pc),d3
  129.     move.l    dosbase(pc),a6
  130.     jsr    -42(a6)            ; read sample data
  131.     bgt.s    transformsample
  132.  
  133.     lea.l    errorreading(pc),a1
  134.     move.l    a1,textptr
  135.     bra.w    error4
  136.  
  137. TRANSFORMSAMPLE:
  138.     move.l    dataptr(pc),a0        ; adjust sample pitch for messy driver
  139.     move.l    filelength(pc),d0
  140.     subq.l    #1,d0
  141.     move.w    eightbit(pc),d2
  142. .loop:    move.b    (a0),d1
  143.     tst.w    d2            ; to six bit if not specified otherwise
  144.     bne.s    .skip
  145.     asr.b    #1,d1            ; transform to max 6 bit sampledata
  146. .skip:    add.b    #128,d1            ; zero -> 128 (they dont use a signbit)
  147.     move.b    d1,(a0)+        ;           (yes sir it is crap!)
  148.     subq.l    #1,d0
  149.     bne.s    .loop
  150.  
  151.     move.l    filelength(pc),d0    ; iffsample length
  152.     sub.l    #64-44,d0        ; min iff header (64)
  153.                     ; plus wav header (44)
  154.  
  155.     subq.l    #8,d0            ; len 1st hunk=total length-headerlen
  156.  
  157.     lea.l    global,a0        ; insert hunklength in hunk structure,
  158.     move.b    d0,(a0)+        ; msdos writes longwords right to left
  159.     asr.l    #8,d0            ; waccydos or what ?
  160.     move.b    d0,(a0)+
  161.     asr.l    #8,d0
  162.     move.b    d0,(a0)+
  163.     asr.l    #8,d0
  164.     move.b    d0,(a0)+
  165.  
  166.     move.l    filelength(pc),d0
  167.     sub.l    #64,d0            ; length raw data (without IFF header)
  168.     lea.l    hunk2,a0        ; insert value in hunk structure
  169.     move.b    d0,(a0)+
  170.     asr.l    #8,d0
  171.     move.b    d0,(a0)+
  172.     asr.l    #8,d0
  173.     move.b    d0,(a0)+
  174.     asr.l    #8,d0
  175.     move.b    d0,(a0)+
  176.  
  177. WRITEHEADER:
  178.     move.l    outhandle(pc),d1
  179.     move.l    #header,d2        ; write RIFF header (44 bytes)
  180.     moveq    #44,d3
  181.     JSR    -48(a6) 
  182.     bgt.s    writesample
  183.  
  184.     lea.l    errorwriting(pc),a1
  185.     move.l    a1,textptr
  186.     bra.s    error4
  187.  
  188. WRITESAMPLE:
  189.     move.l    outhandle(pc),d1
  190.     move.l    dataptr(pc),d2        ; write processed sample data
  191.     move.l    filelength(pc),d3
  192.     jsr    -48(a6)
  193.     bgt.s    .ok1
  194.  
  195.     lea.l    errorwriting(pc),a1
  196.     move.l    a1,textptr
  197.     bra.s    error4
  198.  
  199. .ok1:    move.l    outhandle(pc),d1
  200.     move.l    #credits,d2        ; write credit string
  201.     moveq    #creditslength,d3
  202.     jsr    -48(a6)
  203.     bgt.s    validexit
  204.  
  205.     lea.l    errorwriting(pc),a1
  206.     move.l    a1,textptr
  207.     bra.s    error4
  208.  
  209. VALIDEXIT:
  210.  
  211.     move.l    #valid,textptr
  212. error4:
  213.     move.l    dataptr(pc),a1
  214.     move.l    filelength(pc),d0
  215.     move.l    $4.w,a6
  216.     jsr    -210(a6)        ; freemem
  217.  
  218. error3:
  219.     move.l    dosbase(pc),a6
  220.     move.l    outhandle(pc),d1
  221.     jsr    -$24(a6)        ; close outfile
  222. error2:
  223.     move.l    dosbase(pc),a6
  224.     move.l    inhandle(pc),d1
  225.     jsr    -$24(a6)        ; close infile
  226. error1:
  227.     move.l    textptr(pc),a1
  228.     bsr    puttext
  229.  
  230.     move.l    $4.w,a6
  231.     move.l    dosbase(pc),a1
  232.     jsr    -414(a6)
  233.     movem.l    (sp)+,d0-a6
  234.     rts
  235.  
  236. * * * * * * * *
  237.  
  238. PUTTEXT:movem.l    d0-a6,-(a7)
  239.     move.l    a1,d2
  240.     moveq    #0,d3
  241. .loop:    addq    #1,d3
  242.     tst.b    (a1)+
  243.     bne.s    .loop
  244.     move.l    texthandle(pc),d1
  245.     beq.s    .exit
  246.     move.l    dosbase(pc),a6
  247.     jsr    -48(a6)            ; write text to stdout
  248. .exit:    movem.l    (a7)+,d0-a6
  249.     rts
  250.  
  251. * * * * * * * *
  252.  
  253. dosbase:    dc.l    0
  254. infilenameptr:    dc.l    0
  255. outfilenameptr:    dc.l    0
  256. inhandle:    dc.l    0
  257. outhandle:    dc.l    0
  258. texthandle:    dc.l    0
  259. filelength:    dc.l    0
  260. lock:        dc.l    0
  261. dataptr:    dc.l    0
  262. arglen:        dc.l    0
  263. argptr:        dc.l    0
  264. textptr:    dc.l    syntax
  265. eightbit:    dc.w    0
  266.         dc.l    0
  267.  
  268.         cnop    0,4
  269. infoblock:    blk.b    260,0
  270.  
  271. syntax:        dc.b    10,27,"[0;33m  IFFtoWAV © C00l-G'93",27,"[0m",10
  272.         dc.b    "  Converts Amiga IFF samples to WinSLow's .WAV files",10,10
  273.         dc.b    "  Usage:    IFFtoWAV [-8] <infile> <outfile>",10
  274.         dc.b    "            -8  forces 8 bit samples to be",10
  275.         dc.b    "                created (default is 6 bit)",10,10,0
  276. errorinfile:    dc.b    "Error opening Input File...",10,10,0
  277. erroroutfile:    dc.b    "Error opening Output File...",10,10,0
  278. errorreading:    dc.b    "Error reading Input File...",10,10,0
  279. errorwriting:    dc.b    "Error writing Output File...",10,10,0
  280. outofmem:    dc.b    "Not enough memory !",10,10,0
  281. valid:        dc.b    10,"  Your sample is now converted...",10
  282.         dc.b    "  IFFtoWAV © C00l-G'93",10,10,0
  283. doslibrary:    dc.b    'dos.library',0
  284.         even
  285.  
  286. header:    dc.b    "RIFF"
  287. global:    dc.l    0        ; here comes the total length of the hunkdata
  288.  
  289.     dc.b    "WAVEfmt "
  290. hunk1:    dc.b    16,0,0,0    ; this hunk is always 16 bytes long
  291.  
  292.     dc.b    $01,$00,$01,$00    ; the WAVEfmt hunk (no ID what it is used for!)
  293.     dc.b    $f8,$2a,$00,$00 ; better not change this...
  294.     dc.b    $f8,$2a,$00,$00
  295.     dc.b    $01,$00,$08,$00
  296.  
  297.     dc.b    "data"
  298. hunk2:    dc.l    0        ; here comes the length of the samplehunk
  299.  
  300.  
  301. credits:dc.b    "This sample was converted from AMIGA using C00l-G's "
  302.     dc.b    "IFFtoWAV -- AMIGA: your imagination is "
  303.     dc.b    "the ONLY limit !"
  304.  
  305. endc:
  306. creditslength= endc-credits
  307.